------------------------------------------------------------------------------------------------------------------------------------------------

local function OnAttached(inst,target) -- 玩家得到 debuff 的瞬间。 穿越洞穴、重新进存档 也会执行。
    inst.entity:SetParent(target.entity)
    -- inst.Network:SetClassifiedTarget(target)
    inst.Transform:SetPosition(0,0,0)
    inst.player = target
    -----------------------------------------------------
    --- 计时器
        inst.time = 0
        inst:ListenForEvent("SetTime",function(inst,value)
            inst.time = value
        end)
        local delta_time = 0.2
        inst:DoPeriodicTask(delta_time,function()
            inst.time = inst.time - delta_time
            if inst.time <= 0 then
                inst:Remove()
            end
        end)
    -----------------------------------------------------
    --- 减伤
        if target.components.combat then
            target.components.combat.externaldamagetakenmultipliers:SetModifier(inst,0.3)
        end
    -----------------------------------------------------
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddNetwork()
    inst.entity:AddTransform()

    inst:AddTag("CLASSIFIED")



    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("debuff")
    inst.components.debuff:SetAttachedFn(OnAttached)
    -- inst.components.debuff.keepondespawn = true -- 是否保持debuff 到下次登陆
    -- inst.components.debuff:SetDetachedFn(inst.Remove)
    -- inst.components.debuff:SetDetachedFn(OnDetached)
    -- inst.components.debuff:SetExtendedFn(ExtendDebuff)
    -- ExtendDebuff(inst)

    -- inst:DoPeriodicTask(1, OnUpdate, nil, TheWorld.ismastersim)  -- 定时执行任务


    return inst
end

return Prefab("hutao_debuff_polearm_mastery_spear", fn)
